package com.fxsh168.server.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.fxsh168.server.R;
import com.fxsh168.server.adapters.MyYaoTwoAdapter;
import com.fxsh168.server.base.BaseActivity;
import com.fxsh168.server.entitys.MyYaoTwo;
import com.fxsh168.server.interfaces.Constant;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import java.util.List;

import okhttp3.Call;


public class MyYaoTwoActivity extends BaseActivity implements AdapterView.OnItemClickListener {
    MyYaoTwoAdapter myYaoAdapter;
    ListView lstMyYao;
    String mPhone, token;
    String iid;
    private List<MyYaoTwo.DataBean> data;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_yao_two);
        iid = getIntent().getStringExtra("iid");
        SharedPreferences sp = getSharedPreferences(Constant.LOGINCLASS, MODE_PRIVATE);
        mPhone = sp.getString("mPhone", "");
        token = sp.getString("token", "");
        lstMyYao = (ListView) findViewById(R.id.lstMyYao);
        soldMoney();
        lstMyYao.setOnItemClickListener(this);
    }


    //   分销中心
    public void soldMoney() {
        OkHttpUtils.post().url(Constant.TWOFEN).addParams("iid", iid).build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("tag", "用户端我的邀请二级" + response);
                        MyYaoTwo myYaoTwo = new Gson().fromJson(response, MyYaoTwo.class);
                        String code = myYaoTwo.getCode();
                        data = myYaoTwo.getData();
                        if (code.equals("200")) {
                            myYaoAdapter = new MyYaoTwoAdapter(data, MyYaoTwoActivity.this);
                            lstMyYao.setAdapter(myYaoAdapter);
                        }
                    }
                });
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Intent intent = new Intent(MyYaoTwoActivity.this, MyYaoThreeActivity.class);
        String s = data.get(i).getInvitation_code();
        intent.putExtra("iid", s);
        startActivity(intent);
    }
}
